package com.stu.serive.impl;

import com.stu.Dto.EmpDTO;
import com.stu.context.BaseContext;
import com.stu.mapper.CounsellorINFMapper;
import com.stu.pojo.Emp;
import com.stu.serive.CounsellorINFService;
import com.stu.serive.aTService;
import com.stu.vo.EmpVo;
import com.stu.vo.StuInformationVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
@Slf4j
public class CounsellorINFImpl implements CounsellorINFService {

    @Autowired
    private CounsellorINFMapper counsellorINFMapper;

    /**
     * 查询辅导员个人信息
     * @return
     */
    public EmpVo selectCounsellorInformation() {
        //创建实体对象
        Emp emp = counsellorINFMapper.selectCounsellorInformation(BaseContext.getCurrentId());
        //赋值
        EmpVo empVo = new EmpVo();
        BeanUtils.copyProperties(emp, empVo);
        //判断性别
        if(emp.getGender() == 1){
            empVo.setGender("男");
        }else{
            empVo.setGender("女");
        }
        //职位
        empVo.setJob("辅导员");

        return empVo;
    }

    /**
     * 修改辅导员个人信息
     * @param empDTO
     */
    public void updateCounsellorINF(EmpDTO empDTO) {
        //创建实体
        Emp emp = new Emp();
        //赋值
        BeanUtils.copyProperties(empDTO, emp);
        emp.setUpdateTime(LocalDateTime.now());
        emp.setId(Math.toIntExact(BaseContext.getCurrentId()));
        //操作数据库
        log.info("emp:{}",emp);
        counsellorINFMapper.updateCounsellorINF(emp);
    }
}
